package com.tanhua.server.controller;

import cn.hutool.core.map.MapUtil;
import com.tanhua.server.service.MyCenterService;
import com.tanhua.server.vo.UserInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("users")
@RestController
@Slf4j
public class MyCenterController {

    @Autowired
    private MyCenterService myCenterService;

    /**
     * 根据用户id查询用户信息
     *
     * @param userId 用户id，如果为空，表示查询当前登录人的信息
     * @return
     */
    @GetMapping
    public UserInfoVo queryUserInfoByUserId(@RequestParam(value = "userID", required = false) Long userId) {
        return this.myCenterService.queryUserInfoByUserId(userId);
    }

    /**
     * 保存用户记录
     *
     * @param userInfo
     * @return
     */
    @PutMapping
    public Object saveUserInfo(@RequestBody UserInfoVo userInfo) {
        return this.myCenterService.saveUserInfo(userInfo);
    }

    @PostMapping("/header")
    public Object saveHaeder(@RequestParam("headPhoto") MultipartFile headPhoto){
        return this.myCenterService.saveHaeder(headPhoto);
    }

    /**
     * 是否喜欢
     *
     * @param userId
     * @return
     */
    @GetMapping("{userId}/alreadyLove")
    public Boolean isLike(@PathVariable("userId") Long userId){
        return this.myCenterService.isLike(userId);
    }

    /**
     * 查询互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     *
     * @param page
     * @param pageSize
     * @param nickname
     * @param type
     * @return
     */
    @GetMapping("/friends/{type}")
    public Object queryLikeList(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                @RequestParam(value = "pagesize",defaultValue = "1") Integer pageSize,
                                @RequestParam(value = "nickname",required = false) String nickname,
                                @PathVariable("type") String type){
        return this.myCenterService.queryLikeList(page,pageSize,nickname,type);
    }

    /**
     * 取消喜欢
     *
     * @param likeUserId
     * @return
     */
    @DeleteMapping("/like/{uid}")
    public void disLike(@PathVariable("uid") Long likeUserId){
        this.myCenterService.disLike(likeUserId);
    }

    /**
     * 粉丝,喜欢
     *
     * @param likeUserId
     */
    @PostMapping("/fans/{uid}")
    public void likeUser(@PathVariable("uid") Long likeUserId){
        this.myCenterService.likeUser(likeUserId);
    }
    /**
     * 设置问题
     *
     * @param param
     * @return
     */
    @PostMapping("/questions")
    public Object setQuestion(@RequestBody Map<String, String> param) {
        String content = param.get("content");
        return this.myCenterService.setQuestion(content);

    }

    /**
     * 查看黑名单
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/blacklist")
    public Object queryBlacklist(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pagesize", defaultValue = "20") Integer pageSize) {

        return this.myCenterService.queryBlacklist(page, pageSize);
    }

    /**
     * 删除黑名单
     *
     * @param uid
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public Object deleteBlackUser(@PathVariable("uid") String uid) {

        return this.myCenterService.deleteBlackUser(uid);
    }

    /**
     * 发送验证码
     *
     * @return
     */
    @PostMapping("/phone/sendVerificationCode")
    public Object sendVerificationCode() {
        return this.myCenterService.sendVerificationCode();
    }

    /**
     * 校验验证码
     *
     * @param param
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public Map<String,Boolean> checkVerificationCode(@RequestBody Map<String,String> param) {

        String verificationCode = param.get("verificationCode");
        Boolean o = this.myCenterService.checkVerificationCode(verificationCode);
        Map<String,Boolean> map = new HashMap<>();
        map.put("verification",o);
        return map;
    }

    /**
     * 修改手机号码
     *
     * @param phone
     * @return
     */
    @PostMapping("/phone")
    public Object changePhone(@RequestParam("phone") String phone) {
        return this.myCenterService.changePhone(phone);
    }

    /**
     * 设置,
     *
     * @return
     */
    @GetMapping("/settings")
    public Object settings() {
        return this.myCenterService.settings();
    }

    /**
     * 设置权限保存
     *
     * @param param
     * @return
     */
    @PostMapping("/notifications/setting")
    public Object notificationsSetting(@RequestBody Map<String, Object> param) {

        Object likeNotification = param.get("likeNotification");
        Object pinglunNotification = param.get("pinglunNotification");
        Object gonggaoNotification = param.get("gonggaoNotification");

        return this.myCenterService.notificationsSetting(likeNotification, pinglunNotification, gonggaoNotification);
    }


}
